﻿
namespace Service
{
	using System;
	using System.Linq;
	using Data.Repository;
	using System.Collections.Generic;

	public class OrderService : IOrderService
	{
		private IOrderRepository _orderRepository;

		#region IOrderService Members

		public int CreateNewOrder(Data.Entity.Order theNewOrder)
		{
			if (theNewOrder == null)
			{
				return 0;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.CreateNewOrder(theNewOrder);
		}

		public int CreateNewOrderNote(Data.Entity.OrderNote theNewOrderNote)
		{
			if (theNewOrderNote == null)
			{
				return 0;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.CreateNewOrderNote(theNewOrderNote);
		}

		public IList<Data.Entity.OrderNote> GetOrderNoteByOrder(int orderID)
		{
			if (orderID <= 0)
			{
				return null;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetOrderNoteByOrder(orderID);
		}

		public int DeleteOrder(int id)
		{
			if (id <= 0)
			{
				return 0;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.DeleteOrder(id);
		}

		public IList<Data.Entity.Order> GetOrderByUser(Guid userID)
		{
			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetOrderByUser(userID);
		}

		public IList<Data.Entity.OrderStatus> GetAllOrderStatus()
		{
			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetAllOrderStatus();
		}

		public int UpdateOrder(Data.Entity.Order theOrder)
		{
			if (theOrder == null || theOrder.OrderID <= 0)
			{
				return 0;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.UpdateOrder(theOrder);
		}

		public int DeleteTheOrdersProduct(int orderID, int productID)
		{
			if (orderID <= 0 || productID <= 0)
			{
				return 0;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.DeleteTheOrdersProduct(orderID, productID);
		}

		public IList<Data.Entity.Product> GetTheOrdersProducts(int orderID)
		{
			if (orderID <= 0)
			{
				return null;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetTheOrdersProducts(orderID);
		}

		public int CreateNewOrderProductMapping(Data.Entity.Order_Product_Mapping theNewOrder_Product_Mapping)
		{
			if (theNewOrder_Product_Mapping == null)
			{
				return 0;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.CreateNewOrderProductMapping(theNewOrder_Product_Mapping);
		}

		public Data.Entity.Order GetTheOrderByOrderID(int orderID)
		{
			if (orderID <= 0)
			{
				return null;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetTheOrderByOrderID(orderID);
		}

		public IList<Data.Entity.Order_Product_Mapping> GetOrderProductMappingByOrder(int theOrderID)
		{
			if (theOrderID <= 0)
			{
				return null;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetOrderProductMappingByOrder(theOrderID);
		}

		public IList<Data.Entity.Order> GetOrdersByLanguage(int languageID)
		{
			if (languageID <= 0)
			{
				return null;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetOrdersByLanguage(languageID);
		}

		public Data.Entity.Order GetTheOrderByOrderNumber(string orderNumber)
		{
			if (string.IsNullOrEmpty(orderNumber))
			{
				return null;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetTheOrderByOrderNumber(orderNumber);
		}

		public Data.Entity.OrderStatus GetTheOrderStatusByStatusName(string statusName)
		{
			if (string.IsNullOrEmpty(statusName))
			{
				return null;
			}

			if (_orderRepository == null)
			{
				_orderRepository = new OrderRepository();
			}

			return _orderRepository.GetTheOrderStatusByStatusName(statusName);
		}

		#endregion
	}
}
